package com.bykj.taketurns.findfragment.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bykj.taketurns.R;
import com.bykj.taketurns.findfragment.activity.LevelThreeActivity;
import com.bykj.taketurns.findfragment.activity.SecondaryActivity;
import com.bykj.taketurns.findfragment.bean.SecondaryTextBean;

import java.util.List;


/**
 * Created by Administrator on 2017/8/14.
 */

public class SecondaryTextAdapter extends RecyclerView.Adapter<SecondaryTextAdapter.ViewHolder> {
    private Context context;
    private List<SecondaryTextBean.TwoListBean> list;
    private SecondaryActivity secondaryActivity = new SecondaryActivity();
    public SecondaryTextAdapter(Context context, List<SecondaryTextBean.TwoListBean> oneList) {
        this.context = context;
        this.list = oneList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.sec_text_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tv_secondary_essay_text.setText("\t\t" + list.get(position).getStoryCharacter().getSccontent().substring(0,62) + "....");
        holder.tv_secondary_title_video.setText(list.get(position).getTname());
        holder.tv_secondary_sum_video.setText(list.get(position).getCharacterAllCount() + "");
        holder.tv_secondary_name_video.setText(list.get(position).getStoryCharacter().getUnickname());
        holder.tv_secondary_planting_video.setText(list.get(position).getJcCount() + "次");
        holder.tv_secondary_like_video.setText(list.get(position).getStoryCharacter().getScbrowse()+ "次");
        holder.tv_secondary_review_video.setText(list.get(position).getCountPing() + "");
        holder.tv_secondary_renewal_video.setText(list.get(position).getStoryCharacter().getScaddtime());
        holder.btn_sec_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, LevelThreeActivity.class);
                intent.putExtra("IF", false);
                intent.putExtra("tid",list.get(position).getTid());
                intent.putExtra("title",list.get(position).getTname());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        RelativeLayout btn_sec_text;
        ImageView iv_signboard_video;
        TextView tv_secondary_essay_text;
        TextView tv_secondary_title_video;
        TextView tv_secondary_name_video;
        TextView tv_secondary_planting_video;
        TextView tv_secondary_like_video;
        TextView tv_secondary_review_video;
        TextView tv_secondary_renewal_video;
        TextView tv_secondary_sum_video;
        public ViewHolder(View view) {
            super(view);
            btn_sec_text = view.findViewById(R.id.btn_sec_text);
            iv_signboard_video = view.findViewById(R.id.iv_signboard_video);
            tv_secondary_essay_text = view.findViewById(R.id.tv_secondary_essay_text);
            tv_secondary_title_video = view.findViewById(R.id.tv_secondary_title_video);
            tv_secondary_name_video = view.findViewById(R.id.tv_secondary_name_video);
            tv_secondary_planting_video = view.findViewById(R.id.tv_secondary_planting_video);
            tv_secondary_like_video = view.findViewById(R.id.tv_secondary_like_video);
            tv_secondary_review_video = view.findViewById(R.id.tv_secondary_review_video);
            tv_secondary_renewal_video = view.findViewById(R.id.tv_secondary_renewal_video);
            tv_secondary_sum_video = view.findViewById(R.id.tv_secondary_sum_video);
        }
    }
}
